package com.jerry.huihome.module.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.jerry.huihome.base.BaseApplication;
import com.jerry.huihome.module.home.entity.Live.BodyBean.DynaItemsBean.*;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by LGuipeng on 2016/5/12.
 */
public class GirlViewImgAdapter extends BaseAdapter{
    private final List<DynaImagesBean> list;
    private final Context context;
    private final ImageLoader imageLoader;
    private final DisplayImageOptions options;
    public GirlViewImgAdapter(Context context,List<DynaImagesBean> list){
        this.list = list;
        this.context = context;
        imageLoader = BaseApplication.getApplication().getImageLoader();
        options = BaseApplication.getApplication().getImageOptions();
    }

    @Override
    public int getCount(){
        return list.size();
    }

    @Override
    public DynaImagesBean getItem(int position){
        return list.get(position);
    }

    @Override
    public long getItemId(int position){
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        final ImageView imageView;
        DynaImagesBean imageBean = getItem(position);
        int defaultWidth = (int)(context.getResources().getDisplayMetrics().widthPixels / 3.1);
        if(null == convertView){
            imageView = new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(defaultWidth, defaultWidth));
            imageView.setPadding(8, 8, 8, 8);
        }else{
            imageView = (ImageView) convertView;
        }
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageLoader.displayImage(imageBean.getDetailImg(), imageView, options);

        return imageView;
    }
}
//}
